<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>处理响应</title>
    <script>
        // 从 URL 参数中获取 API URL 和参数
        function getApiUrl() {
            const params = new URLSearchParams(window.location.search);
            const api = params.get('api');
            params.delete('api');
            return `${api}?${params.toString()}`;
        }

        // 当页面加载完成时
        window.onload = function() {
            try {
                // 获取完整的 API URL
                const apiUrl = getApiUrl();
                
                // 使用 XMLHttpRequest 发送请求
                const xhr = new XMLHttpRequest();
                xhr.open('GET', apiUrl, true);
                
                // 设置请求头
                xhr.setRequestHeader('User-Agent', 'Apifox/1.0.0 (https://apifox.com)');
                xhr.setRequestHeader('Accept', '*/*');
                xhr.setRequestHeader('Cookie', 'X_CACHE_KEY=2a863c9e920fee18f85a1fd48da862a2');
                
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                        try {
                            // 保存响应到 localStorage
                            window.opener.localStorage.setItem('tempResponse', xhr.responseText);
                        } catch (error) {
                            console.error('处理响应失败:', error);
                            window.opener.localStorage.setItem('tempResponse', JSON.stringify({
                                code: 500,
                                msg: error.message
                            }));
                        } finally {
                            // 关闭窗口
                            window.close();
                        }
                    }
                };
                
                xhr.onerror = function() {
                    console.error('请求失败');
                    window.opener.localStorage.setItem('tempResponse', JSON.stringify({
                        code: 500,
                        msg: '请求失败'
                    }));
                    window.close();
                };
                
                // 发送请求
                xhr.send();
                
                // 添加超时处理
                setTimeout(() => {
                    if (xhr.readyState !== 4) {
                        xhr.abort();
                        window.opener.localStorage.setItem('tempResponse', JSON.stringify({
                            code: 500,
                            msg: '请求超时'
                        }));
                        window.close();
                    }
                }, 10000);
                
            } catch (error) {
                console.error('处理响应失败:', error);
                window.opener.localStorage.setItem('tempResponse', JSON.stringify({
                    code: 500,
                    msg: error.message
                }));
                window.close();
            }
        };
    </script>
</head>
<body>
    <div style="display: none;">正在处理请求...</div>
</body>
</html> 